package com.zh.utils;

import org.apache.shiro.crypto.hash.Hash;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * @Description: 密码加密工具类
 * @ClassName PasswordGenerateUtil
 * @date: 2021.04.16 13:59
 * @Author: zhanghang
 */
public class PasswordGenerateUtil {
    // 散列次数
    public final static int HASHLTERATIONS = 2;

    // 密码加密工具，
    // username： 盐值
    // password: 加密前的密码
    // HASHLTERATIONS： 散列次数
    public static String getPassword(String username,String password){
        Hash hash = new SimpleHash(Md5Hash.ALGORITHM_NAME, password, ByteSource.Util.bytes(username), HASHLTERATIONS);
        return hash.toHex();
    }

    public static void main(String[] args) {
        System.out.println(getPassword("zhangsan","123456"));
    }
}
